# Hey Emacs, this is a -*- makefile -*-
#
#   Copyright (C) 2006 Pascal Brisset, Antoine Drouin
#
# This file is part of paparazzi.
#
# paparazzi is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# paparazzi is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with paparazzi; see the file COPYING.  If not, write to
# the Free Software Foundation, 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#

#
# This is the Makefile for the JSBSim target.
# Compilator: g++
#

SRC_ARCH = arch/sim

CC = g++
SIMDIR = $(PAPARAZZI_SRC)/sw/simulator
OPT ?= 2

# Launch with "make Q=''" to get full command display
Q=@

#
# Compilation flags
#

CFLAGS	= -W -Wall $(INCLUDES) -I$(PAPARAZZI_SRC)/sw/airborne/$(SRC_ARCH) $($(TARGET).CFLAGS) $(LOCAL_CFLAGS) -O$(OPT)

LDFLAGS		=	-lm $($(TARGET).LDFLAGS)

#
# General rules
#

$(TARGET).srcsnd = $(notdir $($(TARGET).srcs))
$(TARGET).objso	= $($(TARGET).srcs:%.c=$(OBJDIR)/%.o)
$(TARGET).objs	= $($(TARGET).objso:%.S=$(OBJDIR)/%.o)

all compile: check_jsbsim $(OBJDIR) $(OBJDIR)/simsitl


check_jsbsim:
	@echo Paparazzi jsbsim package found: $(JSBSIM_PKG)

$(OBJDIR):
	@echo CREATING object dir $(OBJDIR)
	@test -d $(OBJDIR) || mkdir -p $(OBJDIR)

$(OBJDIR)/simsitl : $($(TARGET).objs)
	@echo LD $@
	$(Q)$(CC) $(CFLAGS) -o $@ $($(TARGET).objs) $(LDFLAGS)


%.s: %.c
	$(CC) $(CFLAGS) -S -o $@ $<

%.s: %.cpp
	$(CC) $(CFLAGS) -S -o $@ $<

$(OBJDIR)/%.s: %.c
	@echo CC $@
	$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
	$(CC) $(CFLAGS) -S -o $@ $<

$(OBJDIR)/%.s: %.cpp
	@echo CC $@
	$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
	$(CC) $(CFLAGS) -S -o $@ $<

$(OBJDIR)/%.o: %.c $(OBJDIR)/../Makefile.ac
	@echo CC $@
	$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
	$(Q)$(CC) -MMD $(CFLAGS) -c -o $@ $<

$(OBJDIR)/%.o: %.cpp $(OBJDIR)/../Makefile.ac
	@echo CC $@
	$(Q)test -d $(dir $@) || mkdir -p $(dir $@)
	$(Q)$(CC) -MMD $(CFLAGS) -c -o $@ $<

.PHONY: all compile check_jsbsim


#
# Dependencies
#

DEPS = $(addprefix $(OBJDIR)/,$($(TARGET).srcs:.c=.d))

ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif
